<?php

/**
 * @author Martin Pernica
 * @copyright 2008
 */
Text::h1( Lang::getBack('com_custom', 'admin') );

if (empty($_GET['a'])) {
    echo '<table cellspacing="15" cellpadding="15">';
    echo '<tr><td><a href="' . $_SERVER['PHP_SELF'] . '?' . $_SERVER['QUERY_STRING'] .
        '&a=new"><img src="../libs/icons/add.png" /> Vytvořit stránku</a></td></tr>';
    echo '</table><br />';


    $query = $GLOBALS['db']->query("SELECT * FROM " . $GLOBALS['db_prefix'] .
        "custom ORDER BY date DESC") or die($GLOBALS['db']->error);
    echo '<table cellspacing="20" cellpadding="30">';
    echo '<tr><th>Název</th><th>Oprávnění</th><th>Datum</th><th>Odkaz</th><th>Akce</th></tr>';
    while ($data = $query->fetch_array()) {
		$seoParser = new SeoUrl();
        $seoParser->Parse($data['title']);
        $seo_url = 'index.php?q=custom/'.$data['id'] . "-" . $seoParser->result;

        echo '<tr><td>' . $data['title'] . '</td><td>' . $data['require_rank'] .
            '</td><td>' . $data['date'] . '</td><td>'.$seo_url.'</td><td><a href="' . $_SERVER['PHP_SELF'] . '?' .
            $_SERVER['QUERY_STRING'] . '&a=delete&id=' . $data['id'] .
            '"><img src="../libs/icons/delete.png" /></a>&nbsp;&nbsp;<a href="' . $_SERVER['PHP_SELF'] .
            '?' . $_SERVER['QUERY_STRING'] . '&a=edit&id=' . $data['id'] .
            '"><img src="../libs/icons/style_edit.png" /></a></td></tr>';
    }
    echo '</table>';

} else {
    switch ($_GET['a']) {
        case 'new':
            require 'new.php';
            break;

        case 'delete':
            require 'delete.php';
            break;

        case 'edit':
            require 'edit.php';
            break;
    }
}
?>